//
//  MMTextStyleView.m
//  MemeMaker
//
//  Created by dangthan on 7/15/13.
//  Copyright (c) 2013 soyo. All rights reserved.
//

#import "MMTextStyleView.h"
#import <QuartzCore/QuartzCore.h>

@implementation MMTextStyleView
@synthesize delegate;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.borderColor = [UIColor blackColor].CGColor;
        self.layer.borderWidth = 1.0;
        textSize = 30.0;
        type = BOLD;
    }
    return self;
}

- (id) initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        self.layer.borderColor = [UIColor blackColor].CGColor;
        self.layer.borderWidth = 1.0;
        textSize = 30.0;
        type = BOLD;
    }
    return self;
}

- (IBAction)buttonClicked:(id)sender {
    UIButton *btn = (UIButton *) sender;
    switch (btn.tag) {
        case 1: {
            [imgFontType setImage:[UIImage imageNamed:@"icon_regular.png"]];
            type = REGULAR;
            if (delegate && [delegate respondsToSelector:@selector(didChangedSize:andFontType:)]) {
                [delegate didChangedSize:textSize andFontType:type];
            }
            break;
        }
        case 2: {
            [imgFontType setImage:[UIImage imageNamed:@"icon_bold.png"]];
            type = BOLD;
            if (delegate && [delegate respondsToSelector:@selector(didChangedSize:andFontType:)]) {
                [delegate didChangedSize:textSize andFontType:type];
            }
            break;
        }
        case 3: {
            [imgFontType setImage:[UIImage imageNamed:@"icon_italic.png"]];
            type = ITALIC;
            if (delegate && [delegate respondsToSelector:@selector(didChangedSize:andFontType:)]) {
                [delegate didChangedSize:textSize andFontType:type];
            }
            break;
        }
        case 4: {
            [imgAlignment setImage:[UIImage imageNamed:@"icon_font1.png"]];
            if (delegate && [delegate respondsToSelector:@selector(didChangedAlignment:)]) {
                [delegate didChangedAlignment:NSTextAlignmentLeft];
            }
            break;
        }
        case 5: {
            [imgAlignment setImage:[UIImage imageNamed:@"icon_font2.png"]];
            if (delegate && [delegate respondsToSelector:@selector(didChangedAlignment:)]) {
                [delegate didChangedAlignment:NSTextAlignmentCenter];
            }
            break;
        }
        case 6: {
            [imgAlignment setImage:[UIImage imageNamed:@"icon_font3.png"]];
            if (delegate && [delegate respondsToSelector:@selector(didChangedAlignment:)]) {
                [delegate didChangedAlignment:NSTextAlignmentRight];
            }
            break;
        }
    
        default:
            break;
    }
}

- (IBAction)textSizeChanged:(id)sender {
    UISlider *slider = (UISlider *)sender;
    if (delegate && [delegate respondsToSelector:@selector(didChangedSize:andFontType:)]) {
        [delegate didChangedSize:slider.value andFontType:type];
    }
    textSize = slider.value;
    lblSize.text = [NSString stringWithFormat:@"%0.1f", slider.value];
}



@end
